<template>
  <el-dialog
    :visible.sync="visible"
    :title="!dataForm.id ? $t('add') : $t('update')"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmitHandle()"
      :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'"
    >
      <el-form-item label="交易类型 买卖" prop="transactionType">
        <el-input v-model="dataForm.transactionType" placeholder="交易类型 买卖"></el-input>
      </el-form-item>
      <el-form-item label="客源类型" prop="customerType">
        <el-input v-model="dataForm.customerType" placeholder="客源类型"></el-input>
      </el-form-item>
      <el-form-item label="客源id" prop="customerId">
        <el-input v-model="dataForm.customerId" placeholder="客源id"></el-input>
      </el-form-item>
      <el-form-item label="房源id" prop="houseId">
        <el-input v-model="dataForm.houseId" placeholder="房源id"></el-input>
      </el-form-item>
      <el-form-item label="房间id" prop="fjId">
        <el-input v-model="dataForm.fjId" placeholder="房间id"></el-input>
      </el-form-item>
      <el-form-item label="产权面积" prop="area">
        <el-input v-model="dataForm.area" placeholder="产权面积"></el-input>
      </el-form-item>
      <el-form-item label="使用面积" prop="sarea">
        <el-input v-model="dataForm.sarea" placeholder="使用面积"></el-input>
      </el-form-item>
      <el-form-item label="成交总价" prop="buyPrice">
        <el-input v-model="dataForm.buyPrice" placeholder="成交总价"></el-input>
      </el-form-item>
      <el-form-item label="付款方式" prop="payType">
        <el-input v-model="dataForm.payType" placeholder="付款方式"></el-input>
      </el-form-item>
      <el-form-item label="首付金额" prop="payments">
        <el-input v-model="dataForm.payments" placeholder="首付金额"></el-input>
      </el-form-item>
      <el-form-item label="首付比例" prop="paymentsRatio">
        <el-input v-model="dataForm.paymentsRatio" placeholder="首付比例"></el-input>
      </el-form-item>
      <el-form-item label="贷款金额" prop="loanPrice">
        <el-input v-model="dataForm.loanPrice" placeholder="贷款金额"></el-input>
      </el-form-item>
      <el-form-item label="贷款银行" prop="loanBank">
        <ren-select
          v-model="dataForm.loanBank"
          dict-type="houseBank"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <el-form-item label="贷款时间" prop="loanTime">
        <el-input v-model="dataForm.loanTime" placeholder="贷款时间"></el-input>
      </el-form-item>
      <el-form-item label="业主税费" prop="ownerTaxation">
        <el-input v-model="dataForm.ownerTaxation" placeholder="业主税费"></el-input>
      </el-form-item>
      <el-form-item label="客户税费" prop="customerTaxation">
        <el-input v-model="dataForm.customerTaxation" placeholder="客户税费"></el-input>
      </el-form-item>
      <el-form-item label="递增" prop="increase">
        <el-input v-model="dataForm.increase" placeholder="递增"></el-input>
      </el-form-item>
      <el-form-item label="房源用途" prop="purpose">
        <ren-select
          v-model="dataForm.purpose"
          dict-type="housePurpose"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <el-form-item label="交房时间" prop="deliverTime">
        <el-input v-model="dataForm.deliverTime" placeholder="交房时间"></el-input>
      </el-form-item>
      <el-form-item label="过户时间" prop="transferTime">
        <el-input v-model="dataForm.transferTime" placeholder="过户时间"></el-input>
      </el-form-item>
      <el-form-item label="交房标准" prop="deliverStandard">
        <el-input v-model="dataForm.deliverStandard" placeholder="交房标准"></el-input>
      </el-form-item>
      <el-form-item label="佣金" prop="commission">
        <el-input v-model="dataForm.commission" placeholder="佣金"></el-input>
      </el-form-item>
      <el-form-item label="业主佣金比例" prop="ownerCommissionRatio">
        <el-input v-model="dataForm.ownerCommissionRatio" placeholder="业主佣金比例"></el-input>
      </el-form-item>
      <el-form-item label="业主佣金" prop="ownerCommission">
        <el-input v-model="dataForm.ownerCommission" placeholder="业主佣金"></el-input>
      </el-form-item>
      <el-form-item label="客户佣金比例" prop="customerCommissionRatio">
        <el-input v-model="dataForm.customerCommissionRatio" placeholder="客户佣金比例"></el-input>
      </el-form-item>
      <el-form-item label="客户佣金" prop="customerCommission">
        <el-input v-model="dataForm.customerCommission" placeholder="客户佣金"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
      <el-form-item label="审核" prop="examine">
        <el-input v-model="dataForm.examine" placeholder="审核"></el-input>
      </el-form-item>
      <el-form-item label="成交人" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="成交人"></el-input>
      </el-form-item>
      <el-form-item label="成交部门" prop="deptId">
        <el-input v-model="dataForm.deptId" placeholder="成交部门"></el-input>
      </el-form-item>
      <el-form-item label="成交时间" prop="dealDate">
        <el-input v-model="dataForm.dealDate" placeholder="成交时间"></el-input>
      </el-form-item>
      <el-form-item label="城市租户" prop="tenantCode">
        <el-input v-model="dataForm.tenantCode" placeholder="城市租户"></el-input>
      </el-form-item>
      <el-form-item label="删除状态" prop="deleteFlag">
        <el-input v-model="dataForm.deleteFlag" placeholder="删除状态"></el-input>
      </el-form-item>
      <el-form-item label="修改人" prop="updater">
        <el-input v-model="dataForm.updater" placeholder="修改人"></el-input>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateDate">
        <el-input v-model="dataForm.updateDate" placeholder="修改时间"></el-input>
      </el-form-item>
    </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from "lodash/debounce";
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: "",
        transactionType: "",
        customerType: "",
        customerId: "",
        houseId: "",
        fjId: "",
        area: "",
        sarea: "",
        buyPrice: "",
        payType: "",
        payments: "",
        paymentsRatio: "",
        loanPrice: "",
        loanBank: "",
        loanTime: "",
        ownerTaxation: "",
        customerTaxation: "",
        increase: "",
        purpose: "",
        deliverTime: "",
        transferTime: "",
        deliverStandard: "",
        commission: "",
        ownerCommissionRatio: "",
        ownerCommission: "",
        customerCommissionRatio: "",
        customerCommission: "",
        remark: "",
        examine: "",
        userId: "",
        deptId: "",
        dealDate: "",
        tenantCode: "",
        deleteFlag: "",
        creator: "",
        createDate: "",
        updater: "",
        updateDate: ""
      }
    };
  },
  computed: {},
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      this.$http
        .get(`/contract/contractsellinfo/${this.dataForm.id}`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.dataForm = {
            ...this.dataForm,
            ...res.data
          };
        })
        .catch(() => {});
    },
    // 表单提交
    dataFormSubmitHandle: debounce(
      function() {
        this.$refs["dataForm"].validate(valid => {
          if (!valid) {
            return false;
          }
          this.$http[!this.dataForm.id ? "post" : "put"](
            "/contract/contractsellinfo/",
            this.dataForm
          )
            .then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            })
            .catch(() => {});
        });
      },
      1000,
      { leading: true, trailing: false }
    )
  }
};
</script>
